package com.bdqn.t382.sz;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class LoggingInvocationHandler implements InvocationHandler {
    private final Object target;

    public LoggingInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 方法执行前的日志
        System.out.println("Before executing method: " + method.getName());

        // 执行目标方法
        Object result = method.invoke(target, args);

        // 方法执行后的日志
        System.out.println("After executing method: " + method.getName());

        return result;
    }
}
